package fatworm.query.constant;

public class DateTime implements Comparable<DateTime> {
	
	private int year, month, day, hour, minute, second;
    private String origin;
	
	public DateTime(String val) {
		
		String[] list = val.split(" ");
		String[] s1 = list[0].split("-");
		year = Integer.parseInt(s1[0]);
		month = Integer.parseInt(s1[1]);
		day = Integer.parseInt(s1[2]);
		
		String[] s2 = list[1].split(":");
		hour = Integer.parseInt(s2[0]);
		minute = Integer.parseInt(s2[1]);
		second = Integer.parseInt(s2[2]);
		
		origin = val;
	}
	
	public boolean equals(Object obj) {
		DateTime dt = (DateTime)obj;
		if (dt == null)
			return false;
		if (dt.year != year)
			return false;
		if (dt.month != month)
			return false;
		if (dt.day != day)
			return false;
		if (dt.hour != hour)
			return false;
		if (dt.minute != minute)
			return false;
		if (dt.second != second)
			return false;
		
		return true;
	}
	
	public int compareTo(DateTime dt) {
		
		if (year > dt.year) 
			return 1;
		else if (year < dt.year)
			return -1;
		
		if (month > dt.month) 
			return 1;
		else if (month < dt.month)
			return -1;
		
		if (day > dt.day) 
			return 1;
		else if (day < dt.day)
			return -1;
		
		if (hour > dt.hour) 
			return 1;
		else if (hour < dt.hour)
			return -1;
		
		if (minute > dt.minute) 
			return 1;
		else if (minute < dt.minute)
			return -1;
		
		if (second > dt.second) 
			return 1;
		else if (second < dt.second)
			return -1;
		
		return 0;
	}
	
	public String toString() {
		return origin;
	}
	
}